package com.hex.ds.hdtp.core.app.script.common.converter;

import com.hex.ds.hdtp.core.app.common.enums.ScriptTableConsanguinityFrom;
import com.hex.ds.hdtp.core.app.script.analyze.dto.response.ScriptAnalyzeListResponseDto;
import com.hex.ds.hdtp.core.app.script.common.dto.request.ScriptTableConsanguinityRequestDto;
import com.hex.ds.hdtp.core.app.script.common.dto.response.ScriptTableConsanguinityResponseDto;
import com.hex.ds.hdtp.core.app.script.transfer.dto.response.ScriptConvertSourceListResponseDto;
import com.hex.ds.hdtp.core.inf.script.common.po.ScriptTableConsanguinityPo;
import com.hex.ds.hdtp.core.inf.script.test.po.ScriptDataTestListPo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.util.List;

/**
 * @Package: com.hex.ds.hdtp.core.app.script.test.converter
 * @ClassName IScriptTableConsanguinityConverter
 * @Description: 脚本表血缘-DTO对象转PO对象转换器
 * @Author: wz.li
 * @Date 2023/8/3 11:16
 * @Version v2.0.2
 **/
@Mapper(componentModel = "spring", imports = {ScriptTableConsanguinityFrom.class})
public interface IScriptTableConsanguinityConverter {

    ScriptTableConsanguinityPo toScriptTestConsanguinityPo(ScriptTableConsanguinityRequestDto scriptTableConsanguinityRequestDto);

    List<ScriptTableConsanguinityResponseDto> toScriptTableConsanguinityResponseDtoList(List<ScriptTableConsanguinityPo> scriptTableConsanguinityPos);

    /**
     * 脚本分析源表
     *
     * @param scriptAnalyzeList
     * @param tableName
     * @return
     */
    @Mapping(target = "pkId", ignore = true)
    @Mapping(target = "taskPkId", source = "scriptAnalyzeList.analyzeTaskPkId")
    @Mapping(target = "scriptListPkId", source = "scriptAnalyzeList.pkId")
    @Mapping(target = "scriptName", source = "scriptAnalyzeList.sourceFileName")
    @Mapping(target = "tableName", source = "tableName")
    @Mapping(target = "tableType", constant = "SOURCE")
    @Mapping(target = "dataFrom", expression = "java(ScriptTableConsanguinityFrom.SCRIPT_ANALYZE.getName())")
    ScriptTableConsanguinityRequestDto toScriptAnalyzeTableConsanguinityForSource(ScriptAnalyzeListResponseDto scriptAnalyzeList, String tableName);

    /**
     * 脚本分析目标表
     *
     * @param scriptAnalyzeList
     * @param tableName
     * @return
     */
    @Mapping(target = "pkId", ignore = true)
    @Mapping(target = "taskPkId", source = "scriptAnalyzeList.analyzeTaskPkId")
    @Mapping(target = "scriptListPkId", source = "scriptAnalyzeList.pkId")
    @Mapping(target = "scriptName", source = "scriptAnalyzeList.sourceFileName")
    @Mapping(target = "tableName", source = "tableName")
    @Mapping(target = "tableType", constant = "TARGET")
    @Mapping(target = "dataFrom", expression = "java(ScriptTableConsanguinityFrom.SCRIPT_ANALYZE.getName())")
    ScriptTableConsanguinityRequestDto toScriptAnalyzeTableConsanguinityForTarget(ScriptAnalyzeListResponseDto scriptAnalyzeList, String tableName);

    /**
     * 脚本测试表血缘
     *
     * @param scriptTableConsanguinityResponseDto
     * @param scriptDataTestListPo
     * @return
     */
    @Mapping(target = "pkId", ignore = true)
    @Mapping(target = "taskPkId", source = "scriptDataTestListPo.taskPkId")
    @Mapping(target = "scriptListPkId", source = "scriptDataTestListPo.pkId")
    @Mapping(target = "scriptName", source = "scriptTableConsanguinityResponseDto.scriptName")
    @Mapping(target = "tableName", source = "scriptTableConsanguinityResponseDto.tableName")
    @Mapping(target = "tableType", source = "scriptTableConsanguinityResponseDto.tableType")
    @Mapping(target = "dataFrom", expression = "java(ScriptTableConsanguinityFrom.SCRIPT_TEST.getName())")
    ScriptTableConsanguinityRequestDto toScriptTableConsanguinityRequestDto(
            ScriptTableConsanguinityResponseDto scriptTableConsanguinityResponseDto,
            ScriptDataTestListPo scriptDataTestListPo);

    /**
     * 脚本转换前源表
     *
     * @param scriptConvertList
     * @param tableName
     * @return
     */
    @Mapping(target = "pkId", ignore = true)
    @Mapping(target = "taskPkId", source = "scriptConvertList.convertTaskPkId")
    @Mapping(target = "scriptListPkId", source = "scriptConvertList.pkId")
    @Mapping(target = "scriptName", source = "scriptConvertList.sourceFileName")
    @Mapping(target = "tableName", source = "tableName")
    @Mapping(target = "tableType", constant = "SOURCE")
    @Mapping(target = "dataFrom", expression = "java(ScriptTableConsanguinityFrom.SCRIPT_CONVERT_SOURCE.getName())")
    ScriptTableConsanguinityRequestDto toScriptOrigTableConsanguinityForSource(ScriptConvertSourceListResponseDto scriptConvertList, String tableName);

    /**
     * 脚本转换前目标表
     *
     * @param scriptConvertList
     * @param tableName
     * @return
     */
    @Mapping(target = "pkId", ignore = true)
    @Mapping(target = "taskPkId", source = "scriptConvertList.convertTaskPkId")
    @Mapping(target = "scriptListPkId", source = "scriptConvertList.pkId")
    @Mapping(target = "scriptName", source = "scriptConvertList.sourceFileName")
    @Mapping(target = "tableName", source = "tableName")
    @Mapping(target = "tableType", constant = "TARGET")
    @Mapping(target = "dataFrom", expression = "java(ScriptTableConsanguinityFrom.SCRIPT_CONVERT_SOURCE.getName())")
    ScriptTableConsanguinityRequestDto toScriptOrigTableConsanguinityForTarget(ScriptConvertSourceListResponseDto scriptConvertList, String tableName);

    /**
     * 脚本转换后源表
     *
     * @param convertTaskPkId
     * @param scriptListPkId
     * @param scriptName
     * @param tableName
     * @return
     */
    @Mapping(target = "taskPkId", source = "convertTaskPkId")
    @Mapping(target = "scriptListPkId", source = "scriptListPkId")
    @Mapping(target = "scriptName", source = "scriptName")
    @Mapping(target = "tableName", source = "tableName")
    @Mapping(target = "tableType", constant = "SOURCE")
    @Mapping(target = "dataFrom", expression = "java(ScriptTableConsanguinityFrom.SCRIPT_CONVERT_TARGET.getName())")
    ScriptTableConsanguinityRequestDto toScriptTableConsanguinityForSource(String convertTaskPkId, String scriptListPkId,
                                                                           String scriptName, String tableName);

    /**
     * 脚本转换后目标表
     *
     * @param convertTaskPkId
     * @param scriptListPkId
     * @param scriptName
     * @param tableName
     * @return
     */
    @Mapping(target = "taskPkId", source = "convertTaskPkId")
    @Mapping(target = "scriptListPkId", source = "scriptListPkId")
    @Mapping(target = "scriptName", source = "scriptName")
    @Mapping(target = "tableName", source = "tableName")
    @Mapping(target = "tableType", constant = "TARGET")
    @Mapping(target = "dataFrom", expression = "java(ScriptTableConsanguinityFrom.SCRIPT_CONVERT_TARGET.getName())")
    ScriptTableConsanguinityRequestDto toScriptTableConsanguinityForTarget(String convertTaskPkId, String scriptListPkId,
                                                                           String scriptName, String tableName);
}
